package com.xxl.job.executor.service.jobhandler;

import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.executor.entity.Goods;
import com.xxl.job.executor.service.IGoodsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;

@Slf4j
@Component
public class MyJob {

  AtomicLong atomicLong = new AtomicLong();

  @Resource
  IGoodsService iGoodsService;

  @XxlJob("myJobHandler")
  public void myJobHandler() throws Exception {
    XxlJobHelper.log("开始执行添加 商品操作");

    Goods goods = new Goods();
    goods.setUuid(UUID.randomUUID().toString().replace("-", ""));
    goods.setName("面粉" + atomicLong.getAndIncrement());
    boolean r = iGoodsService.save(goods);
    //Thread.sleep(5000);
    XxlJobHelper.log("添加参数：{}，添加结果：{}", goods, r);
    log.info("执行成功！：{}", r);
  }


}
